<!-- 账户汇总--付款预估收益明细 -->
<template>
  <div>
    <div class="table-page-search">
      <a-form>
        <a-form-item label="订单编号">
          <a-input v-model="queryParam.orderCode" placeholder="请输入订单编号" allowClear />
        </a-form-item>
        <a-form-item label="业务类型">
          <a-select v-model="queryParam.orderType" placeholder="请选择" allowClear>
            <a-select-option v-for="item in orderTypeDict" :key="item.value" :value="item.value">{{
              item.label
            }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="支付时间">
          <a-range-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="applyTime" class="width-25" />
        </a-form-item>
        <span class="search-submitButtons">
          <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
          <a-button @click="handleReset">重置</a-button>
        </span>
      </a-form>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="id, enabled, title"
      :columns="columns"
      :data="loadData"
      :rowSelection="null"
    >
      <!-- 业务类型 -->
      <span slot="orderType" slot-scope="text">
        {{ orderTypeEnum[text] }}
      </span>

      <!-- 申请人所属协会 -->
      <span slot="orgName" slot-scope="text, record">
        {{ record.orgName }}
      </span>

      <!-- 订单金额 -->
      <span slot="payMoney" slot-scope="text"> ￥{{ text }} </span>

      <!-- 付款预估收益 -->
      <span slot="income" slot-scope="text"> ￥{{ text }} </span>
    </s-table>
  </div>
</template>

<script>
import { STable } from '@/components'
import { IncomeList } from '@/api/finance/finance'
import { orderTypeDict } from '@/api/order/order'
import { orderTypeEnum } from '@/enums/system'
export default {
  components: {
    STable,
  },
  data() {
    return {
      pagination: {
        current: 1,
        pageSize: 10,
      },
      queryParam: {
        orderCode: undefined, //订单号
        orderType: undefined, //订单类型
        startTime: undefined, //支付时间开始
        endTime: undefined, //支付时间结束
      },
      columns: [
        {
          title: '订单号',
          dataIndex: 'orderCode',
          width: '220px',
        },
        {
          title: '订单归属',
          dataIndex: 'orgName',
          ellipsis: true,
          width: '120px',
        },
        {
          title: '业务类型',
          dataIndex: 'orderType',
          ellipsis: true,
          width: '120px',
          scopedSlots: { customRender: 'orderType' },
        },
        {
          title: '申请人',
          dataIndex: 'userName',
          ellipsis: true,
          width: '100px',
        },
        {
          title: '所属协会',
          ellipsis: true,
          width: '120px',
          scopedSlots: { customRender: 'orgName' },
        },
        {
          title: '被链接人',
          dataIndex: 'sourceUsername',
          ellipsis: true,
          width: '120px',
        },
        {
          title: '所属协会',
          dataIndex: 'sourceOrgName',
          ellipsis: true,
          width: '120px',
        },
        {
          title: '订单金额',
          dataIndex: 'payMoney',
          ellipsis: true,
          width: '100px',
          scopedSlots: { customRender: 'payMoney' },
        },
        {
          title: '付款预估收益（元）',
          dataIndex: 'income',
          ellipsis: true,
          width: '180px',
          scopedSlots: { customRender: 'income' },
        },
        {
          title: '支付时间',
          dataIndex: 'playAt',
          ellipsis: true,
          width: '150px',
        },
      ],
      pageNum: 1,
      // 加载数据方法 必须为 Promise 对象
      loadData: async (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        return IncomeList(Object.assign(params, this.queryParam))
          .then((res) => {
            if (res.code === 0) {
              this.pagination.current = parameter.pageNum
              this.pagination.pageSize = parameter.pageSize
              return res
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch((err) => {
            this.$message.error(err.msg)
          })
      },
      orderTypeDict,
      orderTypeEnum,
    }
  },
  computed: {
    applyTime: {
      get() {
        return [this.queryParam.startTime, this.queryParam.endTime]
      },
      set(val) {
        this.queryParam.startTime = val[0]
        this.queryParam.endTime = val[1]
      },
    },
  },
  created() {},
  methods: {
    handleReset() {
      Object.keys(this.queryParam).forEach((k) => {
        this.queryParam[k] = undefined
      })
      this.$refs.table.refresh(true)
    },
  },
}
</script>
<style scoped lang="less">
</style>
